import multineuro.event as event

class AbstractStage(event.Event):
    """ Models a situations in the game """
    def __init__(self):
        super(AbstractStage, self).__init__()

    def finnish(self):
        self.dispatch('finnish', self)

    def begin(self):
        pass #Abstract


class ButtonStage(AbstractStage):
    """ Stage that can be skipped by a button """
    def __init__(self):
        super(ButtonStage, self).__init__()

    def finnish(self, *args, **kwargs):
        self.suscription.unsuscribe()
        super(ButtonStage, self).finnish(*args, **kwargs)

    def begin(self, button, *args, **kwargs):
        self.suscription = button.suscribe('pressed', lambda x: self.finnish())
        super(ButtonStage, self).begin(*args, **kwargs)


class StimuliStage(ButtonStage):
    """ Stage where stimulii are used """
    def __init__(self, stimuli, sprite_repo, *args, **kwargs):
        super(StimuliStage, self).__init__(*args, **kwargs)
        self.position = (500, 100)
        self.stimuli = stimuli
        self.sprite_repo = sprite_repo

    def begin(self, *args, **kwargs):
        super(StimuliStage, self).begin(*args, **kwargs)
        for name in self.stimuli:
            sprite = self.sprite_repo[name]
            sprite.move(self.position)
            sprite.show_sprite()

    def finnish(self, *args, **kwargs):
        super(StimuliStage, self).finnish(*args, **kwargs)
        [self.sprite_repo[x].hide() for x in self.stimuli]

